package com.tarena.lbs.business.dao.repository.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tarena.lbs.business.dao.mapper.BusinessMapper;
import com.tarena.lbs.business.dao.repository.BusinessRepository;
import com.tarena.lbs.business.pojo.po.BusinessPO;
import com.tarena.lbs.business.pojo.po.StorePO;
import com.tarena.lbs.business.pojo.query.BusinessQuery;
import com.tarena.lbs.business.pojo.vo.BusinessVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository
@RequiredArgsConstructor
@Slf4j
public class BusinessRepositoryImpl implements BusinessRepository {
    private final BusinessMapper businessMapper;
    public Page<BusinessPO> getBusinessPageList(BusinessQuery businessQuery) {
        //创建分页对象
        Page<BusinessPO> page = new Page<>(businessQuery.getPageNo(), businessQuery.getPageSize());
        // 创建查询条件
        QueryWrapper<BusinessPO> queryWrapper = new QueryWrapper<>();
        //查询条件添加
        queryWrapper.eq(businessQuery.getBusinessId() != null, "id", businessQuery.getBusinessId());
        queryWrapper.like(businessQuery.getBusinessName() != null, "business_name", businessQuery.getBusinessName());
        queryWrapper.eq(businessQuery.getBusinessHeadPhone() != null, "business_head_phone", businessQuery.getBusinessHeadPhone());
        queryWrapper.eq(businessQuery.getBusinessStatus() != null, "business_status", businessQuery.getBusinessStatus());
        return businessMapper.selectPage(page, queryWrapper);
    }
    public void save(BusinessPO po) {
        businessMapper.insert(po);
    }

    @Override
    public BusinessPO selectOne(LambdaQueryWrapper<BusinessPO> queryWrapper) {
        return businessMapper.selectOne(queryWrapper);
    }
    public int countByBusinessName(String businessName) {
        return businessMapper.countByBusinessName(businessName);
    }
    public List<StorePO> getStoreListByBusinessId(Integer businessId) {
        return businessMapper.getStoreListByBusinessId(businessId);
    }

    @Override
    public BusinessPO selectById(Integer businessId) {
        return businessMapper.selectById(businessId);
    }

    @Override
    public void updateById(BusinessPO businessPO) {
        businessMapper.updateById(businessPO);
    }

    @Override
    public void deleteById(Integer businessId) {
        businessMapper.deleteById(businessId);
    }
}
